package com.jstide.credit.data.service.biz;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Entity;
import com.jstide.credit.data.service.Algorithm;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.ResultSet;
import java.util.Date;
import java.util.List;
import java.util.Optional;

public class Factor26 extends Algorithm {

    private static final Logger logger = LoggerFactory.getLogger(Factor26.class);

    @Getter
    public final  String name="26";

    //若已在黑名单则不扣分，若不在黑名单“一般”-20；“较重”-60；“严重”-80；一般、较重取1年内，严重取3年
    //行政处罚信息
    //-80
    @Getter
    public  final String sql =" select CF_SXYZCD, CF_JDRQ from ZRRXZCFXX where join_id=@joinId  order by CF_JDRQ asc  ";
    @Getter
    public final int defaultScore=50;

    @Override
    public int translate(String rs) {
        return calculate();
    }



    private int calculate() {
        return defaultScore;
    }

    @Override
    public int translate(List<Entity> rs) {
        int score = 0;
        if(null!=rs && rs.size()>0){
            try {
                for(Entity t : rs){
                    Date rq = t.getDate("CF_JDRQ" );
                    String cd = t.getStr("CF_SXYZCD");
                    if(null!=rq){
                        int year = DateUtil.ageOfNow(rq);
                        if(year< 3 ){
                               if(StrUtil.equals("严重",cd)){
                                   return -80;
                               }
                               else if(year <1){
                                   if( StrUtil.equals("一般",cd)){
                                       return  -20;
                                   }
                                   else if(StrUtil.equals("较重",cd)){
                                       return -60;
                                   }
                               }
                        }
                    }
                }
            }catch (Exception e){
                score=0;
            }
        }
        return score;

    }
}
